package com.cosmoplat.xikai.business.controller;

import com.cosmoplat.xikai.business.domain.BaseAlarmRecord;
import com.cosmoplat.xikai.business.domain.dto.alarm.AlarmQueryDTO;
import com.cosmoplat.xikai.business.domain.dto.scada.DeviceFaultDto;
import com.cosmoplat.xikai.business.service.BaseAlarmRecordService;
import com.cosmoplat.xikai.common.core.controller.BaseController;
import com.cosmoplat.xikai.common.core.domain.AjaxResult;
import com.cosmoplat.xikai.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName AlarmManageController
 * @Description 告警管理
 * @Author wdf
 * @Date 2025/1/7
 */
@Api(tags = "告警管理", value = "告警管理")
@RestController
@Slf4j
@RequestMapping("/alarmManage")
public class AlarmManageController extends BaseController {

    @Autowired
    private BaseAlarmRecordService alarmRecordService;


    /**
     * 告警管理查询
     *
     * @param queryDTO
     * @return com.cosmoplat.xikai.common.core.page.TableDataInfo
     * @date 16:22 2025/1/7
     **/
    @ApiOperation(value = "分页查询")
    @PreAuthorize("@ss.hasPermi('business:alarmManage:query')")
    @GetMapping("/queryForPage")
    public TableDataInfo<BaseAlarmRecord> queryForPage(AlarmQueryDTO queryDTO) {
        startPage();
        List<BaseAlarmRecord> list = alarmRecordService.queryForPage(queryDTO);
        return getDataTable(list);
    }

    @ApiOperation(value = "告警统计")
    @PreAuthorize("@ss.hasPermi('business:alarmManage:query')")
    @PostMapping("/alarmStatistics")
    public AjaxResult alarmStatistics(DeviceFaultDto deviceFaultDto) {

        HashMap<String, Long> map = alarmRecordService.alarmStatistics(deviceFaultDto);
        return AjaxResult.success(map);
    }

}
